package com.juno.cafenoa.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class CafeNoaDBDataHelper extends SQLiteOpenHelper {

	public CafeNoaDBDataHelper(Context context) {
		super(context, CafeNoaDBConstants.DB_NAME, null, CafeNoaDBConstants.DE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL( "CREATE TABLE IF NOT EXISTS " + CafeNoaDBConstants.PRODUCT_TABLE + " ( "		+
				CafeNoaDBConstants.PRODUCT_NUM					+ " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,"		+
				CafeNoaDBConstants.PRODUCT_ID					+ " INTEGER NOT NULL ,"		+
				CafeNoaDBConstants.PRODUCT_CATEGORY				+ " INTEGER NOT NULL,"					+
				CafeNoaDBConstants.PRODUCT_NAME					+ " TEXT NOT NULL,"					+
				CafeNoaDBConstants.PRODUCT_PRICE				+ " INTEGER NOT NULL ,"		+
				CafeNoaDBConstants.PRODUCT_IMAGE				+ " TEXT NOT NULL,"					+
				CafeNoaDBConstants.PRODUCT_OPTION				+ " TEXT,"					+
				CafeNoaDBConstants.PRODUCT_CONTENT				+ " TEXT )");
		
		db.execSQL( "CREATE TABLE IF NOT EXISTS " + CafeNoaDBConstants.CATEGORY_TABLE + " ( "		+
				CafeNoaDBConstants.CATEGORY_NUM					+ " INTEGER PRIMARY KEY AUTOINCREMENT ,"		+
				CafeNoaDBConstants.CATEGORY_ID					+ " INTEGER NOT NULL,"		+
				CafeNoaDBConstants.CATEGORY_NAME				+ " TEXT NOT NULL)");

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		db.execSQL( "DROP TABLE IF EXISTS " + CafeNoaDBConstants.PRODUCT_TABLE );
		db.execSQL( "DROP TABLE IF EXISTS " + CafeNoaDBConstants.CATEGORY_TABLE );
		onCreate( db );
	}

}
